package ldh.im.monitor.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import ldh.im.fxbase.data.event.EventBusFactory;
import ldh.im.fxbase.util.MovableHelper;
import ldh.im.fxbase.util.RegionUtil;
import ldh.im.fxbase.util.RpcUtil;
import ldh.im.monitor.controller.sub.SummaryController;
import ldh.im.monitor.controller.sub.UserController;

import java.net.URL;
import java.util.ResourceBundle;

public class MonitorMainController implements Initializable {

    @FXML private Pane headerPane;
    @FXML private Label titleLabel;
    @FXML private Pane contentPane;

    private Object registerObject = null;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        MovableHelper.movable(headerPane);

        titleLabel.setText("宇连通监控客户端");
    }

    @FXML
    private void showSummaryInfoAct(ActionEvent actionEvent) {
        RegionUtil.FxmlBean<Pane, SummaryController> fxmlBean = RegionUtil.loadFxmlBean(this.getClass().getResource("/fxml/sub/SummaryPane.fxml"));
        if (registerObject != null) {
            EventBusFactory.getInstance().unregister(registerObject);
        }
        contentPane.getChildren().setAll(fxmlBean.getNode());
        EventBusFactory.getInstance().register(fxmlBean.getController());
        registerObject = fxmlBean.getController();
    }

    @FXML
    private void showUserInfoAct(ActionEvent actionEvent) {
        RegionUtil.FxmlBean<Pane, UserController> fxmlBean = RegionUtil.loadFxmlBean(this.getClass().getResource("/fxml/sub/UserPane.fxml"));
        if (registerObject != null) {
            EventBusFactory.getInstance().unregister(registerObject);
        }
        contentPane.getChildren().setAll(fxmlBean.getNode());
        EventBusFactory.getInstance().register(fxmlBean.getController());
        registerObject = fxmlBean.getController();
    }
}
